package com.zhiche.lisa.lspm.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.CollectionUtils;
import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import com.zhiche.lisa.core.utils.Account.AccountUtil;
import com.zhiche.lisa.core.utils.Account.JwtAccountVO;
import com.zhiche.lisa.lspm.dao.model.carrier.CarrierCard;
import com.zhiche.lisa.lspm.dao.model.carrier.CarrierDictionary;
import com.zhiche.lisa.lspm.dao.model.carrier.CarrierInfo;
import com.zhiche.lisa.lspm.dao.model.carrier.bo.CarrierInfoLineBO;
import com.zhiche.lisa.lspm.dao.model.carrier.bo.CarrierTrailerBO;
import com.zhiche.lisa.lspm.dao.model.carrier.bo.ModifyCarrierInfoBO;
import com.zhiche.lisa.lspm.dao.model.carrier.bo.VehicleBO;
import com.zhiche.lisa.lspm.dao.model.fleet.Fleet;
import com.zhiche.lisa.lspm.dao.model.trailer.bo.TrailerCarrierBO;
import com.zhiche.lisa.lspm.service.carrier.CarrierDictionaryService;
import com.zhiche.lisa.lspm.service.carrier.ICarrierCardService;
import com.zhiche.lisa.lspm.service.carrier.ICarrierInfoService;
import com.zhiche.lisa.lspm.vo.common.CommonVo;
import com.zhiche.lisa.lspm.vo.driver.AttachVO;
import com.zhiche.lisa.lspm.vo.driver.DriverPlateVO;
import com.zhiche.lisa.lspm.vo.lsp.LspSubVo;
import com.zhiche.lisa.lspm.vo.vehicle.*;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 牵引车 接口
 */
@RestController
@RequestMapping(value = "/carrier")
@Api(value = "/carrier", description = "牵引车接口", tags = {"牵引车接口"})
public class CarrierController {

    private static final Logger LOGGER = LoggerFactory.getLogger(CarrierController.class);

    @Autowired
    private ICarrierInfoService carrierInfoService;
    @Autowired
    private ICarrierCardService carrierCardService;
    @Autowired
    private CarrierDictionaryService dictionaryService;
    

    @PostMapping(value = "/carrierInfoLine")
    @ApiOperation(value = "获取牵引车基础信息列表", notes = "获取牵引车基础信息列表",
            produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<CarrierInfoLineVO>> carrierInfoLine(@RequestBody Page<CarrierInfoLineBO> page,
                                                                    @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.carrierInfoLine（获取牵引车基础信息列表） params : {} ", page);
        RestfulResponse<Page<CarrierInfoLineVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),
                CommonEnum.SUCCESS.getText(), null);
        try {
            Page<CarrierInfoLineVO> pageVo = carrierInfoService.carrierInfoLine(page, authorization);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }

        return result;
    }

    @GetMapping(value = "/listCarrierPlateInfo")
    @ApiOperation(value = "根据名称获取车队", notes = "根据名称获取车队", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Fleet.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<CarrierInfo>> listFleetInfo(@ApiParam(name = "corpName", value = "模糊名称", required = true) String corpName) {
        RestfulResponse<List<CarrierInfo>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        EntityWrapper<CarrierInfo> ew = new EntityWrapper<>();
        ((EntityWrapper) ew).like("plate", corpName);
        JwtAccountVO jwtAccountVO = null;
        if (Objects.isNull(jwtAccountVO = AccountUtil.getAccountInfoFromSecurityContext())) {
            return new RestfulResponse<>(CommonEnum.ERROR.getCode(), "未获取到用户登录信息", null);
        }
        ((EntityWrapper) ew).ne("tenant_id", jwtAccountVO.getTenantId());
        result.setData(carrierInfoService.selectList(ew));
        return result;
    }

    @PostMapping(value = "/authedCarrierLine")
    @ApiOperation(value = "获取认证的牵引车", notes = "获取认证的牵引车", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<CarrierInfoLineVO>> authedCarrierLine(@RequestBody Page<CarrierInfoLineBO> page) {
        LOGGER.info("CarrierController.authCarrierInfoLine（获取认证过的牵引车） params : {} ", page);
        RestfulResponse<Page<CarrierInfoLineVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            Page<CarrierInfoLineVO> pageVo = carrierInfoService.authedCarrierInfoLine(page);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.authedCarrierLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.authedCarrierLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/findModifyInfo")
    @ApiOperation(value = "查找牵引车信息", notes = "查找牵引车信息", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<ModifyCarrierInfoBO> findModifyInfo(Long id) {
        LOGGER.info("CarrierController.findModifyInfo（查找编辑牵引车信息） params : {} ", id);
        RestfulResponse<ModifyCarrierInfoBO> result = new RestfulResponse(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(carrierInfoService.findModifyInfo(id));
        } catch (BaseException e) {
            LOGGER.error("CarrierController.findModifyInfo ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.findModifyInfo ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }

        return result;
    }

    @PostMapping(value = "/getCarrierByLsp")
    @ApiOperation(value = "获取承运商下的牵引车", notes = "获取承运商下的牵引车", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<CarrierDetailVO>> getCarrierByLsp(@RequestBody Page<CarrierDetailVO> page,
                                                                  @RequestHeader("Authorization") String authorization) {

        LOGGER.info("TrailerInfoController.getCarrierByLsp（获取承运商下的牵引车） params : {}", page);

        RestfulResponse<Page<CarrierDetailVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(carrierInfoService.getCarrierByLsp(page, authorization));
        } catch (BaseException e) {
            LOGGER.error("TrailerInfoController.getCarrierByLsp ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("TrailerInfoController.getCarrierByLsp ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }

        return result;
    }

    /**
     * 获取承运商下  认证且 绑定挂车 司机的牵引车信息
     */

    @PostMapping(value = "/queryCarrierByLsp")
    @ApiOperation(value = "获取承运商下  认证且绑定挂车/司机的牵引车信息", notes = "获取承运商下  认证且绑定挂车/司机的牵引车信息",
            produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<CarrierDetailVO>> queryCarrierByLsp(@RequestBody Page<CarrierDetailVO> page,
                                                                    @RequestHeader("Authorization") String authorization) {

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("TrailerInfoController.queryCarrierByLsp params : {}", page);
        }
        RestfulResponse<Page<CarrierDetailVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),
                CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(carrierInfoService.queryCarrierByLsp(page, authorization));
        } catch (BaseException e) {
            LOGGER.error("TrailerInfoController.getCarrierByLsp BaseException {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("TrailerInfoController.getCarrierByLsp ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }

        return result;
    }

    /**
     * 停用牵引车
     */
    @PostMapping(value = "/discontinuatCarrier")
    @ApiOperation(value = "停用牵引车", notes = "停用牵引车", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<List<String>> discontinuatCarrier(@RequestBody CommonVo commonVo) {
        LOGGER.info("CarrierController.discontinuatCarrier（停用牵引车） params : {} ", commonVo.toString());
        RestfulResponse<List<String>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<String> msgs = carrierInfoService.discontinuatCarrier(commonVo.getCarrierIds());
            if (!CollectionUtils.isEmpty(msgs)) {
                result = new RestfulResponse<>(CommonEnum.ERRORLIST.getCode(), "部分停用失败", msgs);
            }
        } catch (BaseException e) {
            LOGGER.error("CarrierController.discontinuatCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.discontinuatCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    /**
     * 启用牵引车
     */
    @PostMapping(value = "/enableCarrier")
    @ApiOperation(value = "启用牵引车", notes = "启用牵引车", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<List<String>> enableCarrier(@RequestBody CommonVo commonVo) {
        LOGGER.info("CarrierController.enableCarrier（启用牵引车） params : {} ", commonVo.toString());

        RestfulResponse<List<String>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<String> msgs = carrierInfoService.enableCarrier(commonVo.getCarrierIds());
            if (!CollectionUtils.isEmpty(msgs)) {
                result = new RestfulResponse<>(CommonEnum.ERRORLIST.getCode(), "部分启用失败", msgs);
            }
        } catch (BaseException e) {
            LOGGER.error("CarrierController.enableCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.enableCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/authCarrier")
    @ApiOperation(value = "认证牵引车", notes = "认证牵引车", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse authCarrier(@RequestBody CommonVo commonVo, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.authCarrier（认证牵引车） params : {} ", commonVo.toString());
        RestfulResponse result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<String> msg = carrierInfoService.batchUpdateAuthStatusByIds(commonVo.getCarrierIds(), authorization);
            if (!CollectionUtils.isEmpty(msg)) {
                result = new RestfulResponse<>(CommonEnum.ERRORLIST.getCode(), "部分认证失败", msg);
            }
        } catch (BaseException e) {
            LOGGER.error("CarrierController.authCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.authCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }

        return result;
    }

    @PostMapping(value = "/cancelAuthCarrier")
    @ApiOperation(value = "取消认证牵引车", notes = "取消认证牵引车", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse cancelAuthCarrier(@RequestBody CommonVo commonVo) {
        LOGGER.info("CarrierController.cancelAuthCarrier（停用牵引车） params : {} ", commonVo.toString());
        RestfulResponse result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            carrierInfoService.batchUpdateCancelAuthStatusByIds(commonVo.getCarrierIds());
        } catch (BaseException e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/getCarrierInfoByPlate")
    @ApiOperation(value = "根据车牌号获取牵引车信息", notes = "根据车牌号获取牵引车信息", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<CarrierInfoLineVO> getCarrierInfoByPlate(String plate) {
        LOGGER.info("CarrierController.getCarrierInfoByPlate（根据车牌号获取牵引车信息） params : {} ", plate);
        RestfulResponse<CarrierInfoLineVO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(carrierInfoService.getCarrierInfoByPlate(plate));
        } catch (BaseException e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }

        return result;
    }

    @GetMapping(value = "/authedCarrierPlate")
    @ApiOperation(value = "获取所有已经认证的牵引车车牌", notes = "获取所有已经认证的牵引车车牌", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<List<String>> authedCarrierPlate(String plate) {
        LOGGER.info("CarrierController.获取所有已经认证的牵引车车牌（根据车牌号获取牵引车信息） params : {} ", plate);
        RestfulResponse<List<String>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(carrierInfoService.authedCarrierPlate());
        } catch (BaseException e) {
            LOGGER.error("CarrierController.获取所有已经认证的牵引车车牌 ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.获取所有已经认证的牵引车车牌 ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/authedTenantPlate")
    @ApiOperation(value = "获取租户下的已经认证的牵引车牌", notes = "获取租户下的已经认证的牵引车牌", produces = MediaType.APPLICATION_JSON_VALUE,
            response = RestfulResponse.class)
    public RestfulResponse<List<String>> authedTenantPlate(String tenantId) {
        LOGGER.info("CarrierController.authedTenantPlate 获取租户下的已经认证的牵引车牌 params:{}", tenantId);
        RestfulResponse<List<String>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(carrierInfoService.authedTenantPlate(Long.parseLong(tenantId)));
        } catch (BaseException e) {
            LOGGER.error("CarrierController.authedTenantPlate 获取租户下的已经认证的牵引车牌 ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.authedTenantPlate 获取租户下的已经认证的牵引车牌 ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/changeLsp/transferCarrier")
    @ApiOperation(value = "转移牵引车所属承运商", notes = "转移牵引车所属承运商",
            produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<String> changeCarrierLsp(@RequestBody LspSubVo lspSubVo, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.changeCarrierLsp 转移牵引车所属承运商 params:{}", lspSubVo);
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),
                null);
        try {
            carrierInfoService.changeLspAndRemoveRelation(lspSubVo.getIds(), lspSubVo.getLspId(), lspSubVo.getIsAllTransfer(), authorization);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.changeCarrierLsp 转移牵引车所属承运商 ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.changeCarrierLsp 转移牵引车所属承运商 ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/carrierTrailer")
    @ApiOperation(value = "获取牵引车与挂车列表", notes = "获取牵引车与挂车列表", produces = MediaType.APPLICATION_JSON_VALUE, response =
            RestfulResponse.class)
    public RestfulResponse<Page<CarrierTrailerBO>> queryCarrierTrailer(@RequestBody Page<CarrierTrailerBO> page,
                                                                       @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.carrierInfoLine（获取牵引车与挂车列表） params : {} ", page);
        RestfulResponse<Page<CarrierTrailerBO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            Page<CarrierTrailerBO> pageVo = carrierInfoService.queryPageCarrierTrailer(page, authorization);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }


    @ApiOperation(value = "获取牵引车可绑定挂车", notes = "获取牵引车可绑定挂车",
            produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carrierId", value = "牵引车ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "trailerPlate", value = "挂车车牌", required = true, dataType = "String")})
    @PostMapping(value = "/usableTrailer")
    public RestfulResponse<List<TrailerCarrierBO>> queryUsableTrailer(@RequestBody CarrierTrailerBindVO carrierTrailerBindVO, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.carrierInfoLine（获取牵引车的可用挂车） params : {} ", carrierTrailerBindVO);

        RestfulResponse<List<TrailerCarrierBO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);

        try {
            List<TrailerCarrierBO> listData = carrierInfoService.queryUsableTrailer
                    (carrierTrailerBindVO.getCarrierId(), carrierTrailerBindVO.getTrailerPlate(), authorization);
            result.setData(listData);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @ApiOperation(value = "牵引车绑定挂车", notes = "牵引车绑定挂车", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carrierId", value = "牵引车ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "trailerPlate", value = "挂车ID", required = true, dataType = "Long")})
    @PostMapping(value = "/bindTrailer")
    public RestfulResponse<Boolean> bindTrailer(@RequestBody CarrierTrailerBindVO carrierTrailerBindVO, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.carrierInfoLine（获取牵引车的可用挂车） params : {}", carrierTrailerBindVO);

        RestfulResponse<Boolean> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),
                null);
        try {
            Boolean bool = carrierInfoService.bingTrailer(carrierTrailerBindVO.getCarrierId(),
                    carrierTrailerBindVO.getTrailerId(), carrierTrailerBindVO.getTenantId(), authorization);
            result.setData(bool);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/unbindTrailer")
    @ApiOperation(value = "解绑牵引车与挂车", notes = "解绑牵引车与挂车", produces = MediaType.APPLICATION_JSON_VALUE, response =
            RestfulResponse.class)
    public RestfulResponse<Boolean> unbindTrailer(@RequestBody CarrierTrailerBindVO carrierTrailerBindVO, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.carrierInfoLine（获取牵引车与挂车列表） params : {} ", carrierTrailerBindVO);
        RestfulResponse<Boolean> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),null);
        try {
            for (CarrierTrailerBO carrierTrailerBO : carrierTrailerBindVO.getCarrierTrailers()) {
                carrierInfoService.unbingTrailer(carrierTrailerBO.getId(), carrierTrailerBO.getTrailerId(), authorization);
            }
            result.setData(true);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/deleteCarrier")
    @ApiOperation(value = "删除牵引车", notes = "删除牵引车", produces = MediaType.APPLICATION_JSON_VALUE, response =
            RestfulResponse.class)
    public RestfulResponse deleteCarrier(@RequestBody CommonVo commonVo) {
        LOGGER.info("CarrierController.cancelAuthCarrier（删除牵引车） params : {} ", commonVo.toString());
        RestfulResponse result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<String> msgs = carrierInfoService.deleteByIds(commonVo.getCarrierIds());
            if (!CollectionUtils.isEmpty(msgs)) {
                result = new RestfulResponse<>(CommonEnum.ERRORLIST.getCode(), "部分牵引车删除失败", msgs);
            }
        } catch (BaseException e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    //---来源于原driver

    /**
     * 司机修改车辆信息
     */
    @RequestMapping(value = "/submitVehicle", method = RequestMethod.POST)
    @ApiOperation(value = "司机修改车辆信息", notes = "司机修改车辆信息", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Object> submitVehicle(@RequestBody VehicleVO vehicleVO,
                                                 @RequestHeader("Authorization") String authorization) {
        LOGGER.info("VehicleController.submitVehicle param: {}", vehicleVO);
        RestfulResponse<Object> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            carrierInfoService.submitVehicle(vehicleVO, authorization);
        } catch (BaseException be) {
            LOGGER.error("VehicleController.submitVehicle error: {}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("VehicleController.submitVehicle error: {}", e.getMessage());
            result.setMessage("提交车辆信息失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    @RequestMapping(value = "/updateVehicleAttach", method = RequestMethod.POST)
    @ApiOperation(value = "司机修改车辆信息", notes = "司机修改车辆信息", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Object> updateVehicleAttach(@RequestBody AttachVO attachVO) {
        LOGGER.info("VehicleController.updateVehicleAttach param: {}", attachVO);
        RestfulResponse<Object> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            carrierInfoService.submitVehicleAttach(attachVO);
        } catch (BaseException be) {
            LOGGER.error("VehicleController.updateVehicleAttach error: {}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("VehicleController.updateVehicleAttach error: {}", e.getMessage());
            result.setMessage("提交车辆信息失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    /**
     * 获取车辆信息
     */
    @RequestMapping(value = "/getVehicle/{driverId}", method = RequestMethod.GET)
    @ApiOperation(value = "获取车辆信息", notes = "获取车辆信息", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<VehicleVO> getVehicle(@PathVariable Long driverId) {
        LOGGER.info("VehicleController.getVehicle param: {}", driverId);
        RestfulResponse<VehicleVO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            VehicleBO vehicleBO = carrierInfoService.getVehicleByDriverId(driverId);
            VehicleVO vehicleVO = new VehicleVO();
            BeanUtils.copyProperties(vehicleBO, vehicleVO);
            CarrierInfoVO carrierInfoVO = new CarrierInfoVO();
            TrailerInfoVO trailerInfoVO = new TrailerInfoVO();
            BeanUtils.copyProperties(vehicleBO.getCarrierInfo(), carrierInfoVO);
            vehicleVO.setCarrierInfo(carrierInfoVO);
            BeanUtils.copyProperties(vehicleBO.getTrailerInfo(), trailerInfoVO);
            vehicleVO.setTrailerInfo(trailerInfoVO);
            result.setData(vehicleVO);
        } catch (BaseException be) {
            LOGGER.error("VehicleController.getVehicle error: {}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("VehicleController.getVehicle error: {}", e.getMessage());
            result.setMessage("获取车辆信息失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    @PostMapping(value = "/unbindCarrier")
    @ApiOperation(value = "取消与牵引车的绑定", notes = "取消与牵引车的绑定", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<VehicleVO> unbindCarrier(@RequestBody DriverPlateVO driverPlateVO) {
        LOGGER.info("VehicleController.unbindCarrier param: {}", driverPlateVO);
        RestfulResponse<VehicleVO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {

            VehicleBO vehicleBO = carrierInfoService.unbindVehicle(driverPlateVO.getDriverId(), driverPlateVO.getPlate());
            VehicleVO vehicleVO = new VehicleVO();
            BeanUtils.copyProperties(vehicleBO, vehicleVO);
            CarrierInfoVO carrierInfoVO = new CarrierInfoVO();
            TrailerInfoVO trailerInfoVO = new TrailerInfoVO();
            BeanUtils.copyProperties(vehicleBO.getCarrierInfo(), carrierInfoVO);
            vehicleVO.setCarrierInfo(carrierInfoVO);
            BeanUtils.copyProperties(vehicleBO.getTrailerInfo(), trailerInfoVO);
            vehicleVO.setTrailerInfo(trailerInfoVO);
            result.setData(vehicleVO);
        } catch (BaseException be) {
            LOGGER.error("VehicleController.verifyTrailer error: {}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("VehicleController.verifyTrailer error: {}", e.getMessage());
            result.setMessage("取消绑定失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    @PostMapping(value = "/queryVehicle")
    @ApiOperation(value = "分页查询牵引车信息", notes = "分页查询牵引车信息",
            produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<WeChatVehicle>> queryVehicle
            (@RequestBody Page<WeChatVehicle> page, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.carrierInfoLine（获取牵引车基础信息列表） params : {} ", page);
        RestfulResponse<Page<WeChatVehicle>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            Page<WeChatVehicle> pageVo = carrierInfoService.queryPageVehicle(page, authorization);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.queryVehicle ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.queryVehicle ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    /**
     * 更改牵引车信息
     */
    @PostMapping(value = "/updateCarrier")
    @ApiOperation(value = "牵引车新增/修改操作", notes = "更改牵引车操作",
            produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<CarrierInfo> updateCarrier(@RequestBody CarrierInfo carrierInfo) {
        LOGGER.info("CarrierController.updateCarrier（更改牵引车操作） params : {} ", carrierInfo.toString());
        RestfulResponse<CarrierInfo> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            CarrierInfo carrierResult = carrierInfoService.updateCarrier(carrierInfo);
            result.setData(carrierResult);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.updateCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.updateCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }

        return result;
    }

    /**
     * 根据id获取牵引车
     */
    @GetMapping(value = "/getCarrier")
    @ApiOperation(value = "获取牵引车", notes = "获取牵引车", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<CarrierBasicVO> getCarrier(Long carrierId) {
        LOGGER.info("CarrierController.getCarrier（获取牵引车） params : {} ", carrierId);
        RestfulResponse<CarrierBasicVO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),
                null);
        try {
            result.setData(carrierInfoService.getCarrierInfoLine(carrierId));
        } catch (BaseException e) {
            LOGGER.error("CarrierController.getCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.getCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/getCard")
    @ApiOperation(value = "获取牵引车卡照", notes = "获取牵引车卡照", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<List<CarrierCard>> getCard(Long carrierId) {
        LOGGER.info("CarrierController.getCard（获取牵引车卡照） params : {} ", carrierId);
        RestfulResponse<List<CarrierCard>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),
                null);
        try {
            EntityWrapper<CarrierCard> lspCardew = new EntityWrapper<>();
            lspCardew.eq("carrier_id", carrierId);
            List<CarrierCard> l = carrierCardService.selectList(lspCardew);
            result.setData(l);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.getCard ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.getCard ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/updateCard")
    @ApiOperation(value = "更新牵引车卡照", notes = "更新牵引车卡照", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<String> updateCard(@RequestBody CarrierCardVO carrierCardVO) {
        LOGGER.info("CarrierController.updateCard（更新牵引车卡照） params : {} ", carrierCardVO);
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),
                null);
        try {
            for (CarrierCard carrierCard :
                    carrierCardVO.getCarrierCards()) {
                if (Objects.nonNull(carrierCard.getId())) {
                    carrierCardService.updateById(carrierCard);
                } else {
                    JwtAccountVO jwtAccount = AccountUtil.getAccountInfoFromSecurityContext();
                    if (Objects.nonNull(jwtAccount)) {
                        carrierCard.setCreator(jwtAccount.getAccountId());
                    }
                    carrierCard.setCarrierId(carrierCardVO.getCarrierId());
                    carrierCardService.insert(carrierCard);
                }
            }
        } catch (BaseException e) {
            LOGGER.error("CarrierController.updateCard ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.updateCard ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/updateDeleteStatus")
    @ApiOperation(value = "恢复牵引车删除状态", notes = "恢复牵引车删除状态", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "操作失败", response = Object.class)})
    public RestfulResponse<List<String>> updateDeleteStatus(@RequestBody List<Long> ids) {
        LOGGER.info("CarrierController.updateDeleteStatus（恢复牵引车删除状态） params : {} ", ids);
        RestfulResponse<List<String>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            List<String> msgs = carrierInfoService.updateDeleteStatus(ids);
            if (!CollectionUtils.isEmpty(msgs)) {
                result = new RestfulResponse<>(CommonEnum.ERRORLIST.getCode(), "部分牵引车删除失败", msgs);
            }
        } catch (BaseException e) {
            LOGGER.error("CarrierController.updateDeleteStatus BaseException {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.updateDeleteStatus ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        }
        return result;
    }

    @GetMapping(value = "/vehicleToOtm/{lspId}")
    @ApiOperation(value = "车俩推otm", notes = "车俩推otm", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "操作失败", response = String.class)})
    public RestfulResponse<String> vehicleToOtm(@PathVariable Long lspId, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.vehicleToOtm（车俩推otm） params : {} ", lspId);
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            carrierInfoService.vehicleToOtm(lspId, authorization);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.vehicleToOtm BaseException... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.vehicleToOtm ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        }
        return result;
    }

    /**
     * 查询数据字典--分页
     */
    @PostMapping("/queryDictionaryPage")
    public RestfulResponse<Page<CarrierDictionary>> queryDictionary(@RequestBody Page<CarrierDictionary> page) {
        RestfulResponse<Page<CarrierDictionary>> response = new RestfulResponse<>(0, "查询成功", null);
        try {
            List<CarrierDictionary> list = dictionaryService.queryDictionary(page);
            page.setRecords(list);
            response.setData(page);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.queryDictionaryPage BaseException:{}", e.getMessage());
            response.setCode(-1);
            response.setMessage(e.getMessage());
        } catch (Exception e) {
            LOGGER.error("CarrierController.queryDictionaryPage error:{}", e.getMessage());
            response.setCode(-1);
            response.setMessage("系统异常");
        }
        return response;
    }
}
